<template>
  <div class="app-container">
  
    <div class="filter-container">
      <el-input v-model="courseId"  placeholder="Please input" style="width: 300px;" class="filter-item"  />
      <el-button style="width: 100px" class="filter-item" type="primary" icon="el-icon-search" @click="searchId(courseId)">Search</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit">Add</el-button>
    </div>
    
    <el-table

      :data="list"

      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="courseId" width="110">
        <template slot-scope="scope">
          {{ scope.row.courseId }}
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="ClassName" width="120">
        <template slot-scope="scope">
          {{ scope.row.className }}
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="classID" width="120">
        <template slot-scope="scope">
          {{ scope.row.classID }}
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="stuNumber" width="120">
        <template slot-scope="scope">
          {{ scope.row.stuNumber }}
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="Leader" width="120">
        <template slot-scope="scope">
          {{ scope.row.leader }}
        </template>
      </el-table-column>
      
      <el-table-column label="Actions" align="center" width="230" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="editCP()">Edit</el-button>
         
          <el-button  size="mini" type="danger" @click="deleteCP(scope.$index, scope.row)">Delete</el-button>
          </template>
      </el-table-column>

    </el-table>
  </div>
</template>

<script>
import { getList } from '@/api/classes/classTable'
import { delTableRow } from "../../../api/classes/classTable";
import { searchList } from "../../../api/classes/classTable";

export default {

  filters: {
    statusFilter(status) {
      const statusMap = {
        published: "success",
        draft: "gray",
        deleted: "danger"
      };
      return statusMap[status];
    }
  },
  data() {
    return {
      list: [
        {
        "courseId":	"javaee软件开发",
      	"classID":	"软件181",
		"Grade": "大一",
		"stuNumber": "71",
        }
      ],
      
      name:'',
      courseId:''
    };
  },

 created() {
    this.fetchData()
  },
  difyStatus(row, status) {
      this.$message({
        message: '操作Success',
        type: 'success'
      })
      row.status = status
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleDelete(row, index) {
      this.$notify({
        title: 'Success',
        message: 'Delete Successfully',
        type: 'success',
        duration: 2000
      })
      this.list.splice(index, 1)
    },
    handleUpdate(row) {
      this.temp = Object.assign({}, row) // copy obj
      this.temp.timestamp = new Date(this.temp.timestamp)
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
  methods: {
  	  editCP(){
      this.$router.push("/editClasses/index")
      }, 
      
      deleteCP(idx,row){
          console.log("索引",idx);
          console.log("数据", row.courseId);
      delTableRow(row.courseId).then((res) => {
        console.log(res)
      })
      alert("删除成功！");
      },
      searchId(courseId){
        var vm = this;
        //console.log(typeof (courseId));
          searchList(undefined, Number(courseId)).then(res => {
            console.log(res);
            vm.list = [];
            var a = vm.list.push(JSON.parse(res));
          //vm.list = res;
           console.log(a);
           console.log(this.list)
        })
      },
  
      fetchData() {
        var vm = this;
        getList().then(res => {
          console.log(res.content)
          vm.list = res.content
        })
      }
    }
}
</script>
